package info.rflow;

import info.rflow.graph.model.RBlockNode;
import info.rflow.graph.util.ObjectSceneListenerAdapter;
import org.netbeans.api.visual.model.ObjectSceneEvent;

import java.util.Set;


/**
 * @author Holger Brandl
 */
class WorkflowSceneListener extends ObjectSceneListenerAdapter {

    private RFlow designer;
    private WorkflowContext workflowContext;


    public WorkflowSceneListener(RFlow designer) {
        this.designer = designer;
    }


    public void selectionChanged(ObjectSceneEvent event, Set<Object> previousSelection, Set<Object> newSelection) {
        if (newSelection.size() == 1) {
            Object o = newSelection.iterator().next();
            if (o instanceof RBlockNode) {
                designer.sourceArea.setBlock(((RBlockNode) o).getRBlock());
            }

            workflowContext.getWorkflowScene().getView().requestFocusInWindow();
        }
    }


    public void setContext(WorkflowContext controller) {
        workflowContext = controller;
    }
}
